#include ".\mygameprocessbar.h"

CMyGameProcessBar::CMyGameProcessBar(void)
{
	m_strShowText = "ProceessBar";
	m_fPercent = 0.0f;
	m_nLastTime = GetTickCount();
}

CMyGameProcessBar::~CMyGameProcessBar(void)
{
}

void CMyGameProcessBar::LoadRes(string strBackFileName,string strFrameFileName,string strFillFileName)
{
	m_sprBack.Load(NULL,strBackFileName.c_str());
	m_sprFrame.Load(NULL,strFrameFileName.c_str());
	m_sprFill.Load(NULL,strFillFileName.c_str());
}
void CMyGameProcessBar::Update()
{
	if (GetTickCount() - m_nLastTime > 100)
	{
		if (m_fPercent > 1.0f)
		{
			m_fPercent = 0.0f;
		}
		m_fPercent += 0.01f;
		m_nLastTime = GetTickCount();
	}
}

void CMyGameProcessBar::Draw(HDC hDC)
{
	CMyGameWindow::Draw(hDC);
	m_sprBack.Draw(hDC,m_ptScreenPos.x,m_ptScreenPos.y);
	m_sprFrame.Draw(hDC,m_ptScreenPos.x,m_ptScreenPos.y,TRUE);
	UINT nWidth = m_fPercent * m_sprFill.GetWidth();
	m_sprFill.DrawRect(hDC,m_ptScreenPos.x,m_ptScreenPos.y,0,0,nWidth,m_sprFill.GetHeight(),TRUE);
	char szBuf[256] = {0};
	sprintf(szBuf,"%d",int(m_fPercent * 100.0f));
	m_strShowText = szBuf;
	SIZE size;
	GetTextExtentPoint32(hDC,m_strShowText.c_str(),m_strShowText.length(),&size);
	TextOut(hDC,m_ptScreenPos.x + m_nWidth / 2 - size.cx /2,m_ptScreenPos.y + m_nHeight /2 - size.cy / 2,m_strShowText.c_str(),m_strShowText.length());
}
